// pages/bookRank/bookRank.js
const http = require("../../utils/http")
const app = getApp()
Page({
  data: {
    rankArray: [], //获取排行榜列表数据
    // hdIndex: 0, //头部索引
    show: true,
    active: 0,
    leftSideIndex: 0, //左边索引
    rightSideUrl: null,
    rightData: null,
    boxHeight: '', //盒子高度
  },
  onLoad: function (options) {
    this.getRank(options)
    this.setData({
      leftSideIndex: options.nowIndex,
      // active:1
    })
    app.watch(this.watchBack)
  },
  // 获取排行榜列表
  getRank(k) {
    wx.showLoading({
      title: '正在加载...',
    })
    http.get("store/merged/rankNavi.json", {
      rankType: k.rankType,
      uuid: k.uuid
    }).then(res => {
      console.log('获取排行榜列表', res.list);
      let fristUrl = res.list[0].subNavis[this.data.leftSideIndex].naviInfos[0].url
      this.getRightData(fristUrl)
      this.setData({
        rankArray: res.list
      })
    })
  },
  // 左边高亮索引
  clickSide(event) {
    // console.log(event.target.dataset.sideurl);
    this.getRightData(event.target.dataset.sideurl[0].url)
    this.setData({
      leftSideIndex: event.target.dataset.sideindex,
      rightSideUrl: event.target.dataset.sideurl[0].url
    })
  },
  // 头部高亮索引
  clickNav(event) {
    let _index = event.detail.index
    let nowUrl = this.data.rankArray[_index].subNavis[this.data.leftSideIndex].naviInfos[0].url
    console.log('nowUrl', nowUrl);
    this.setData({
      leftSideIndex: 0
    })
    // // 获取数据
    this.getRightData(nowUrl)
  },
  // 获取 右边 书籍数据
  getRightData(k) {
    wx.showLoading({
      title: '正在加载...',
    })
    http.get(k).then(res => {
      wx.hideLoading()
      this.setData({
        rightData: res
      })
      // console.log('--获取 右边 书籍数据----->',res);
    })
  },
  // 动态获取内容高度
  getHeight() {
    wx.createSelectorQuery().select(".box").boundingClientRect((rect) => {
      console.log(rect);
    }).exec()
    // console.log('-----H----',this.data.boxHeight);
  },
  watchBack(value) {
    // console.log(value);
    this.setData({
      boxHeight: value
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('触底了----');
  },
  onShow() {
    // this.selectComponent('#tabs').resize();
    this.setData({
      show: false
    })
    // console.log(options.nowIndex)
    setTimeout(() => {
      this.setData({
        show: true
      })
    }, 1300)
  }
})